﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJ.Data.WCF;

namespace PJ.Data
{
    public static class EntityFragmentWCFProxyProvider 

    {   
        public static string[] GetFragments(IEntityFragmentWCFProvider clientBase, IEntityFragmentCache cache,  string sessionId, string ownerId, GetDataMode mode)
        {
            if (ownerId == null || ownerId == "")
                throw new ArgumentNullException("ownerId");
            string [] fragments = null;
            if (cache != null && (mode & GetDataMode.UseCache) == GetDataMode.UseCache)
                fragments = cache.FindFragments(ownerId);
            if (fragments == null)
            {
                fragments = clientBase.GetFragments(sessionId, ownerId, (int)mode);
                if (fragments != null && cache != null)
                    cache.AddFragments(ownerId, fragments);
            }
            else
                return fragments;
            if (fragments == null && (mode & GetDataMode.Find) != GetDataMode.Find)
                throw new DataNotFoundException("ownerId", ownerId);
            return fragments;
        }

    }
}

